import * as Cesium from "cesium";
export const init = () => {
  const viewer = new Cesium.Viewer("cesiumContainer", {
    animation: false,
    fullscreenButton: false,
    vrButton: false,
    geocoder: false,
    homeButton: false,
    sceneModePicker: false,
    timeline: false,
    // terrain: Cesium.Terrain.fromWorldTerrain()
  });

  //   const pointCollect = viewer.scene.primitives.add(new Cesium.PointPrimitiveCollection());

  //   for (let i = 0; i < 200; i++) {
  //     for (let j = 0; j < 200; j++) {
  //       pointCollect.add({
  //         position: Cesium.Cartesian3.fromDegrees(i, j * 0.1 ),
  //         color: Cesium.Color.fromRandom({ alpha: 1.0 }),
  //         pixelSize: 1,
  //         outlineColor: Cesium.Color.RED,
  //         outlineWidth: 1
  //       });
  //     }
  //   }
  const polygon = new Cesium.PolygonGeometry({
    polygonHierarchy: new Cesium.PolygonHierarchy(
      Cesium.Cartesian3.fromDegreesArray([-109.0, 30.0, -95.0, 30.0, -95.0, 40.0, -109.0, 40.0])
      // [new Cesium.PolygonHierarchy(
      // Cesium.Cartesian3.fromDegreesArray([
      //   -107.0, 31.0,
      //   -107.0, 39.0,
      //   -97.0, 39.0,
      //   -97.0, 31.0
      // ]))]
    ),
    // polygonHierarchy : new Cesium.PolygonHierarchy(
    //   Cesium.Cartesian3.fromDegreesArray([
    //     -72.0, 40.0,
    //     -70.0, 35.0,
    //     -75.0, 30.0,
    //     -70.0, 30.0,
    //     -68.0, 40.0
    //   ])
    // )
  });
  const geometry = Cesium.PolygonGeometry.createGeometry(polygon);
  const instance = new Cesium.GeometryInstance({ geometry: geometry });
  console.log(geometry, instance);
  viewer.scene.primitives.add(
    new Cesium.Primitive({
      geometryInstances: instance,
      appearance: new Cesium.MaterialAppearance({
        aboveGround: true,
        // translucent: false,
        // closed: true,
        material: new Cesium.Material({
          fabric: {
            type: "Image",
            uniforms: {
              // color: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
              image: 'image/bg.png',
              // repeat: new Cesium.Cartesian2(10, 10),
              // color: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
            },
          },
        }),
      }),
      // appearance: new Cesium.PerInstanceColorAppearance(),
      asynchronous: false,
      //   appearance: new Cesium.MaterialAppearance({
      //     material: Cesium.Material.fromType("Color"),
      //     faceForward: true
      //   })
      // appearance: new Cesium.MaterialAppearance({
      //   material: new Cesium.Material({
      //     fabric: {
      //       type: "Color",
      //       uniforms: {
      //         color: new Cesium.Color(1.0, 1.0, 0.0, 1.0)
      //       }
      //     }
      //   })
      // })
    })
  );
  //   viewer.zoomTo(pr);
};
